// pages/mywallet/mywallet.js
const app = getApp();
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
   
    spenorincome:[
      {types:"收益",date:"08-23",money:"156",text:"作品收益"},
      { types: "支出", date: "08-23", money: "156", text: "作品收益" },
      { types: "收益", date: "08-23", money: "156", text: "作品收益" },
      { types: "支出", date: "08-23", money: "156", text: "作品收益" }
    ],
    headsrc: app.data.imgurl +"judgess.png",  // 头像
    circle:app.data.imgurl +"circle.png",  //圈圈
    recharge:app.data.imgurl +"recharge.png",
    cashwithdrawl:app.data.imgurl +"cashwithdrawl.png",
    getuserinfo: app.data.url +'sheyingjia/Xmyuser1/getuserinfo',
    getsouyilist: app.data.url + 'sheyingjia/Myorders/getsouyilist',
    users:{},
    page:1,
    shuju:[]

  },


  torecharge:function(){

     wx.navigateTo({
       url: '/pages/recharge/recharge',
     })
  },
  tocashwithdrawal: function () {

    wx.navigateTo({
      url: '/pages/cashwithdrawal/cashwithdrawal',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getuser();
    // this.getsouy();
  },
  //获取用户信息
  getuser:function(){
    var user = wx.getStorageSync('user');
    var that = this;
    ea.qinqiu(that.data.getuserinfo,{token:user.token},function(data){
      console.log(data);
      var users = data.user;
      that.setData({users:users});
    })
  },
  //获取订单列表
  getsouy:function(){
    var user = wx.getStorageSync('user');
    var page = this.data.page;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none'
      })
      return;
    }
    var that = this;
    ea.qinqiu(that.data.getsouyilist, { token: user.token, page: page},function(res){
      // console.log(res);
      if(res.length<10){
        that.setData({page:0});
      }else{
        that.setData({ page: page+1 });
      }
      var shuju = that.data.shuju;
      shuju = ea.addArray(shuju,res);
      console.log(shuju);
      that.setData({shuju:shuju});
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({shuju:[],page:1});
    this.getsouy();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getsouy();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})